<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-row>
        <a-col :span="2">
              </a-col>
        <a-col :span="22" class="ant-table-right">
          <a-button type="primary" @click="handleAdd" shape="circle" icon="plus"></a-button>
          <a-button class="ant-ui-noborder" icon="bar-chart" @click="handleExportXls('用户信息')">导出</a-button>
          <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
            <a-button class="ant-ui-noborder" icon="folder-open">导入</a-button>
          </a-upload>
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel">
                <a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/> </a-button>
          </a-dropdown>
        </a-col>
      </a-row>
    </div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
            <a-col :md="6" :sm="8">
            <a-form-item label="申请人">
                <a-input v-model="queryParam.createName"/>
            </a-form-item>
           </a-col>


          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button  shape="circle" @click="searchQuery" icon="search"></a-button>
              <a @click="searchReset" icon="reload" style="margin-left: 8px">重置</a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
            <a @click="handleSubmit(record)">提交</a>

          <a-divider type="vertical"/>
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <acteLeave-modal ref="modalForm" @ok="modalFormOk"></acteLeave-modal>
  </a-card>
</template>

<script>
  import ActeLeaveModal from './modules/ActeLeaveModal'
  import { HjListMixin } from '@/mixins/HjListMixin'
  import {initDictOptions, filterDictText} from '@/components/dict/JDictSelectUtil'
  import { httpAction, getAction, putAction } from '@/api/manage'

  export default {
    name: "ActeLeaveList",
    mixins:[HjListMixin],
    components: {
      ActeLeaveModal
    },
    data () {
      return {
        description: '管理页面',




        //字典值-所属部门
        sysOrgCodeDictOptions:[],
        //字典值-单证类型
        typeDictOptions:[],
        //字典值-是否加急
        dispatchDictOptions:[],
         //审批状态
        appStatusOptions: [],

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
		   {
            title: '申请人',
            align:"center",
            dataIndex: 'createName',
           },
		   {
            title: '所属部门',
            align:"center",
            dataIndex: 'sysOrgCode',
             customRender: (text, record, index) => {
             //字典值替换通用方法
             return filterDictText(this.sysOrgCodeDictOptions, text);
            }
           },
		   {
            title: '出差事项',
            align:"center",
            dataIndex: 'reason',
           },
		   {
            title: '出差开始时间',
            align:"center",
            dataIndex: 'beginDate',
           },
		   {
            title: '出差结束时间',
            align:"center",
            dataIndex: 'endDate',
           },
		   {
            title: '是否加急',
            align:"center",
            dataIndex: 'dispatch',
             customRender: (text, record, index) => {
             //字典值替换通用方法
             return filterDictText(this.dispatchDictOptions, text);
            }
           },
		   {
            title: '申请日期',
            align:"center",
            dataIndex: 'createTime',
           },
           {
            title: '审批状态',
            align: 'center',
            dataIndex: 'appstatus',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              return filterDictText(this.appStatusOptions, text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
		url: {
          list: "/acteLeave/list",
          delete: "/acteLeave/delete",
          deleteBatch: "/acteLeave/deleteBatch",
          exportXlsUrl: "acteLeave/exportXls",
          importExcelUrl: "acteLeave/importExcel",
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {


      initDictConfig() {
        //初始化字典-所属部门
        initDictOptions('sys_depart,depart_name,org_code').then((res) => {
          if(res.success){
            this.sysOrgCodeDictOptions = res.result;
          }
      })
        //初始化字典-单证类型
        initDictOptions('document').then((res) => {
          if(res.success){
            this.typeDictOptions = res.result;
          }
      })
        //初始化字典-是否加急
        initDictOptions('status_en').then((res) => {
          if(res.success){
            this.dispatchDictOptions = res.result;
          }
      })
       //审批状态
      initDictOptions('bpm_status').then((res) => {
          if (res.success) {
            this.appStatusOptions = res.result
          }
        })
      },

      //提交
      handleSubmit(record){
        getAction('/acteLeave/submit',{id:record.id}).then((res) => {
          if (res.success) {
            this.$message.success("申请成功")
          } else {
            this.$message.warning(res.message)
          }
        })
      }

    }
  }

</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>